package cn.buk.tms.eotms.controller;

import cn.buk.tms.eotms.report.dto.*;
import cn.buk.tms.eotms.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {

  @Autowired
  public ReportController(ReportService service) {
    this.service = service;
  }

  private final ReportService service;

  /**
   * 月报: 合并所有的项目
   */
  @GetMapping("/monthly")
  public MonthlyReport searchMonthlyReport(HttpServletRequest request,
                                                               @RequestParam("beginDate") Date beginDate,
                                                               @RequestParam("endDate") Date endDate) {
    return service.searchMonthlyReport(getUserId(request), beginDate, endDate);
  }

  /**
   * 出票月报
   */
  @RequestMapping("/monthly/flight")
  public List<ReportFlightTicketDto> searchFlightTicketMonthly(HttpServletRequest request,
                                                               @RequestParam("beginDate") Date beginDate,
                                                               @RequestParam("endDate") Date endDate) {
    return service.searchFlightMonthlySale(getUserId(request), beginDate, endDate);
  }

  /**
   * 退票月报(账单）
   */
  @RequestMapping("/monthly/refund")
  public List<ReportFlightRefundDto> searchFlightRefundMonthly(HttpServletRequest request,
                                                               @RequestParam("beginDate") Date beginDate,
                                                               @RequestParam("endDate") Date endDate) {
    return service.searchFlightRefundMonthly(getUserId(request), beginDate, endDate);
  }

  /**
   * 改签月报(账单）
   */
  @RequestMapping("/monthly/change")
  public List<ReportFlightChangeDto> searchFlightChangeMonthly(HttpServletRequest request,
                                                               @RequestParam("beginDate") Date beginDate,
                                                               @RequestParam("endDate") Date endDate) {
    return service.searchFlightChangeMonthly(getUserId(request), beginDate, endDate);
  }

  /**
   * vas月报(账单）
   */
  @RequestMapping("/monthly/vas")
  public List<ReportVasDto> searchVasMonthly(HttpServletRequest request,
                                             @RequestParam("beginDate") Date beginDate,
                                             @RequestParam("endDate") Date endDate) {
    return service.searchVasMonthly(getUserId(request), beginDate, endDate);
  }

  /**
   * 酒店月报(账单）
   */
  @RequestMapping("/monthly/hotel")
  public List<ReportHotelDto> searchHotelMonthly(HttpServletRequest request,
                                                 @RequestParam("beginDate") Date beginDate,
                                                 @RequestParam("endDate") Date endDate) {
    return service.searchHotelMonthly(getUserId(request), beginDate, endDate);
  }

  /**
   * 火车票月报(账单）
   */
  @RequestMapping("/monthly/train")
  public List<ReportTrainDto> searchTrainMonthly(HttpServletRequest request,
                                                 @RequestParam("beginDate") Date beginDate,
                                                 @RequestParam("endDate") Date endDate) {
    return service.searchTrainMonthly(getUserId(request), beginDate, endDate);
  }

  /**
   * 统计日报
   */
  @RequestMapping("/statistic/daily")
  public List<ReportStatDailyDto> statDailySaleStat(HttpServletRequest request,
                                                    @RequestParam("beginDate")
                                                    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate beginDate,
                                                    @RequestParam("endDate")
                                                    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {

    return service.statDailySale(getUserId(request), beginDate, endDate);
  }

  /**
   * 航空公司统计
   */
  @RequestMapping("/statistic/airlines")
  public List<ReportStatisticDto> statMonthSaleByAirlines(HttpServletRequest request,
                                                          @RequestParam("beginDate") Date beginDate,
                                                          @RequestParam("endDate") Date endDate
  ) {
    return service.statMonthSaleByAirlines(getUserId(request), beginDate, endDate);
  }
}
